﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.SilverlightMediaFramework.Plugins.Primitives;

namespace Ausy.Silverlight.VideoPlayer.MediaModule.ViewParts
{
    /// <summary>
    /// Cette classe représente l'affichage du Screencast
    /// </summary>
    public partial class ScreencastView : UserControl, IScreencastView
    {
        #region Model property

        /// <summary>
        /// Model presentation attaché à la vue ScreencastView
        /// </summary>
        public IScreencastViewModel Model
        {
            get { return this.DataContext as IScreencastViewModel; }
            set { this.DataContext = value; }
        }

        #endregion

        #region IsPlaying DependencyProperty

        /// <summary>
        /// Property IsPlaying
        /// </summary>
        public bool IsPlaying
        {
            get { return (bool)GetValue(IsPlayingProperty); }
            set { SetValue(IsPlayingProperty, value); }
        }

        /// <summary>
        /// Dependency Property IsPlaying
        /// Using a DependencyProperty as the backing store for MyProperty.  This enables animation, styling, binding, etc...
        /// </summary>
        public static readonly DependencyProperty IsPlayingProperty = DependencyProperty.Register("IsPlaying", typeof(bool), typeof(ScreencastView), new PropertyMetadata(false, new PropertyChangedCallback(OnIsPlayingChanged)));

        /// <summary>
        /// Method handle the property changement
        /// </summary>
        /// <param name="dep">Represents an ownerclass that participates in the Silverlight dependency property</param>
        /// <param name="e">data for a System.Windows.PropertyChangedCallback implementation.</param>
        private static void OnIsPlayingChanged(DependencyObject dep, DependencyPropertyChangedEventArgs e)
        {
            var sender = dep as ScreencastView;
            if (sender != null)
            {
                if (Convert.ToBoolean(e.NewValue))
                {                   
                    sender.mySMFPlayer.Play();
                    sender.IsPlaying = false;
                }
            }
        }

        #endregion

        #region Constructor

        /// <summary>
        /// Constructeur par défaut
        /// </summary>
        public ScreencastView()
        {
            InitializeComponent();
        }

        #endregion
        
    }
}
